//
//  LoginApi.swift
//  mac-wky
//
//  Created by Apple on 2018/2/8.
//  Copyright © 2018年 Apple. All rights reserved.
//

import Foundation
import Moya
import RxSwift
import RxCocoa

enum Result {
    case a
    case b
}

protocol LoginApi {
    static var shared: LoginApi { get }
    
    func login(phone: String, pwd: String) -> Driver<LoginRst>
}

class XLoginApi: LoginApi {

    static var shared: LoginApi = XLoginApi()
    private let provider = MoyaProvider<ApiTarget>()
    
    func login(phone: String, pwd: String) -> Driver<LoginRst> {
        return provider
            .rx
            .request(.login(phone: phone, pwd: pwd))
            .mapModel(LoginRst.self)
            .asDriver(onErrorRecover: { err in
                print("err: \(err)")
                return Driver.empty()
            })
        
    }
}
